(() => {
	let ele = {};
	let h_id = location.search.split("?")[1];
	ele.top_img = $("#top_img");
	ele.modal_upgradation = $("#modal-upgradation");
	ele.btn_que3 = $("#btn_que3");
	ele.shuomig = $("#shuomig");
	ele.modal_illustrate = $("#modal-illustrate");
	ele.chahao2 = $("#chahao2");
	ele.chahao3 = $("#chahao3");
	ele.bot = $("#bot");
	ele.btn_queren = $("#btn_queren");
	ele.modal_confirm = $("#modal-confirm");
	ele.dangqian = $("#dangqian");
	ele.dangqian_Lv = $("#dangqian_Lv");
	ele.ahengji_Lv = $("#ahengji_Lv");
	ele.left_deng = $("#left_deng");
	ele.right_deng = $("#right_deng");
	ele.cheng_name1 = $("#cheng_name1");
	ele.cheng_name2 = $("#cheng_name2");
	ele.right_h = $("#right_h");
	ele.right_r = $("#right_r");
	ele.left_r = $("#left_r");
	ele.left_h = $("#left_h");
	ele.yongyou = $("#yongyou");
	ele.bot_t = $("#bot_t");
	ele.left_chuang = $("#left_chuang");
	ele.right_chuang = $("#right_chuang");
	ele.modal_road = $('#modal-road');
	ele.close_road = $('#close-road');
	ele.modalbtn = $('#modalbtn');
	ele.buffList = $('#buffList');
	let list = ["", ""];
	let detail = {};
	let id = null;

	// 刘欣 引导 2023-6-22 14:46:20
	ele.top_img.onclick = () => {
		let ugid = guide.getUsersGuideId();
		if (~[128].indexOf(ugid)) guide.hideCentury_128();
		history.back();
	};

	// 关闭 获取途径
	ele.close_road.onclick = () => {
		closeMdl(ele.modal_road);
	}

	// todo点击说明玩法后的x
	ele.chahao2.onclick = () => {
		closeMdl(ele.modal_illustrate);
	};
	// todo点击说明玩法后的确认
	ele.btn_que3.onclick = () => {
		closeMdl(ele.modal_illustrate);
	};
	// todo点击问好
	ele.shuomig.onclick = () => {
		openMdl(ele.modal_illustrate);
	};
	// todo确认装修点击x
	ele.chahao3.onclick = () => {
		closeMdl(ele.modal_confirm);
	};
	// todo确认装修
	ele.btn_queren.onclick = () => {
		zhuangxiu(id);
	};
	// !请求数据
	let bagList = '';
	let _data = '';

	asyncList();

	function asyncList() {
		let token = getCookie("token");
		ajax({
			method: "get",
			url: API_PATH.FURNIT,
			header: {
				Authorization: token,
			},
			success: (res) => {
				list = res.data.list;
				detail = res.data.detail;
				bagList = res.data.list
				_data = res.data.list
				initList();
			},
			error: (err) => {
				// openTips(err.msg);
			},
		});
	}

	realList();



	// 背包列表
	function realList() {
		let token = getCookie("token");
		ajax({
			url: API_PATH.REAL_LIST,
			method: 'GET',
			header: {
				'Authorization': token,
			},
			success: res => {
				if (res.code == 1) {
					// bagList = res.data.menu_list
					// _data = res.data.menu_list
				} else openTips(res.msg || '未知错误');
			}
		});
	}

	// <div style="display:${
	//   item.now == 0 ? "block" : "none"
	// };" class="zhihui"></div>

	// !渲染数据
	function initList() {
		//todo 名字渲染
		ele.cheng_name1.innerHTML = `${detail.home_name}专属`;
		ele.cheng_name2.innerHTML = `${detail.home_name}专属`;
		let html = '';
		for (let i = 0; i < _data.length; i++) {
			let cls = _data[i].now == 0 ? "zhihui" : ""
			console.log(cls);
			html += `<div class="bot_list">
    <div class="zong">
      <div style="background: url('http://img.qxgs.cc/tiantianlaishouzu/img/reward/${h_id}.png') no-repeat; background-size: 100% 100%;" class="left_img1 left_img3  ${cls}">
        <img class="" src="http://img.qxgs.cc/tiantianlaishouzu/img/reward/${_data[i].id}_${_data[i].now}.png" alt="" />
      </div>
      <div class="center">
        <p class="t">${_data[i].name} <span>(${detail.home_name}专属)</span></p>
     
             <p style="display:${
               _data[i].now == 0 ? "block" : "none"
             };" class="c">当前等级：<span>未激活</span></p>
        <p style="display:${
          _data[i].now == 1 ? "block" : "none"
        };" class="c">当前等级：<span>初级</span></p>
        <p style="display:${
          _data[i].now == 2 ? "block" : "none"
        };" class="c">当前等级：<span>中级</span></p>
        <p style="display:${
          _data[i].now == 3 ? "block" : "none"
        };" class="c">当前等级：<span>高级</span></p>
        <p class="b">当前豪华值：<span>${_data[i].now_luxury}</span></p>
      </div>
    </div>
    <div>
    <div class="right_btn" id="right_btn_lv"  style="display:${
      _data[i].has_lv != 0 && _data[i].now == 0 ? "block" : "none"
    };" data-ind="${i}" data-id="${_data[i].has_lv}" data-now="${
          _data[i].now
        }" id="right_btn">使用</div>
    <div class="right_btn" style="display:${
      _data[i].has_lv == 0 && _data[i].now == 0 ? "block" : "none"
    };" data-ind="${i}" data-id="${_data[i].id}" data-now="${
          _data[i].now
        }" id="right_btn">激活</div>
    <div class="right_btn" style="display:${
      _data[i].now != 0 ? "block" : "none"
    };" data-ind="${i}" data-id="${_data[i].id}" data-now="${
          _data[i].now
        }" id="right_btn">升级</div>
    <div class="right_btn2" style="display:${
      _data[i].now > 0 ? "block" : "none"
    };" data-ind="${i}" data-id="${_data[i].now_lv.jj_id}" data-now="${
          _data[i].now
        }" id="right_btn2">卸下</div>
  </div>
  </div>`


		}
		// 当前豪华值
		// console.log(html);
		ele.bot.innerHTML = html
		ele.dangqian.innerHTML = detail.luxury;
		// let newList = list
		// 	.map((item, index) => {
		// 		return `
		//   <div class="bot_list">

		//   <div class="zong">
		//     <div style="background: url('http://img.qxgs.cc/tiantianlaishouzu/img/reward/${h_id}.png') no-repeat; background-size: 100% 100%;" class="left_img1 left_img3">

		//       <img src="http://img.qxgs.cc/tiantianlaishouzu/img/reward/${item.id}_${item.now}.png" alt="" />
		//     </div>
		//     <div class="center">
		//       <p class="t">${item.name} <span>(${detail.home_name}专属)</span></p>

		//            <p style="display:${
		//              item.now == 0 ? "block" : "none"
		//            };" class="c">当前等级：<span>未激活</span></p>
		//       <p style="display:${
		//         item.now == 1 ? "block" : "none"
		//       };" class="c">当前等级：<span>初级</span></p>
		//       <p style="display:${
		//         item.now == 2 ? "block" : "none"
		//       };" class="c">当前等级：<span>中级</span></p>
		//       <p style="display:${
		//         item.now == 3 ? "block" : "none"
		//       };" class="c">当前等级：<span>高级</span></p>
		//       <p class="b">当前豪华值：<span>${item.now_luxury}</span></p>
		//     </div>
		//   </div>
		//   <div>
		//   <div class="right_btn" id="right_btn_lv"  style="display:${
		//     item.has_lv != 0 && item.now == 0 ? "block" : "none"
		//   };" data-ind="${index}" data-id="${item.has_lv}" data-now="${
		//         item.now
		//       }" id="right_btn">使用</div>
		//   <div class="right_btn" style="display:${
		//     item.has_lv == 0 && item.now == 0 ? "block" : "none"
		//   };" data-ind="${index}" data-id="${item.id}" data-now="${
		//         item.now
		//       }" id="right_btn">激活</div>
		//   <div class="right_btn" style="display:${
		//     item.now != 0 ? "block" : "none"
		//   };" data-ind="${index}" data-id="${item.id}" data-now="${
		//         item.now
		//       }" id="right_btn">升级</div>
		//   <div class="right_btn2" style="display:${
		//     item.now > 0 ? "block" : "none"
		//   };" data-ind="${index}" data-id="${item.now_lv.jj_id}" data-now="${
		//         item.now
		//       }" id="right_btn2">卸下</div>
		// </div>
		// </div>`;
		// 	})
		// 	.join(" ");
		// ele.bot.innerHTML = newList;
		// !渲染背景图
		// if(){
		// <div class="right_btn" data-ind="${index}" data-id="${item.id}" data-now="${
		//   item.now
		// }" id="right_btn">${item.now == 0 ? "激活" : "升级"}</div>
		// }
		// !点击升级
		let right_btnAll = document.querySelectorAll("#right_btn");
		let right_btnAll2 = document.querySelectorAll("#right_btn2");
		right_btnAll.forEach((item, index) => {
			item.onclick = () => {
				let arr = list.filter((ite) => ite.id == item.dataset.id);
				if (!arr[0].next_lv) openTips("已经升级最高级");
				// todo当前等级
				ele.dangqian_Lv.innerHTML =
					` <img src="http://img.qxgs.cc/tiantianlaishouzu/img/reward/${arr[0].id}_${arr[0].now_lv.level}.png" alt="" />`;
				ele.dangqian_Lv.style.background =
					`url('http://img.qxgs.cc/tiantianlaishouzu/img/reward/${item.dataset.ind}.png') no-repeat`;
				ele.dangqian_Lv.style.backgroundSize = `100% 100%`;
				//todo 升级后的等级
				ele.ahengji_Lv.innerHTML =
					` <img src="http://img.qxgs.cc/tiantianlaishouzu/img/reward/${arr[0].id}_${arr[0].next_lv.level}.png" alt="" />`;
				ele.ahengji_Lv.style.background =
					`url('http://img.qxgs.cc/tiantianlaishouzu/img/reward/${item.dataset.ind}.png') no-repeat`;
				ele.ahengji_Lv.style.backgroundSize = `100% 100%`;
				// todo渲染等级
				if (arr[0].now_lv.level == 0) {
					ele.left_deng.innerHTML = `未激活`;
				} else if (arr[0].now_lv.level == 1) {
					ele.left_deng.innerHTML = `初级`;
				} else if (arr[0].now_lv.level == 2) {
					ele.left_deng.innerHTML = `中级`;
				} else if (arr[0].now_lv.level == 3) {
					ele.left_deng.innerHTML = `高级`;
				}
				if (arr[0].next_lv.level == 0) {
					ele.right_deng.innerHTML = `未激活`;
				} else if (arr[0].next_lv.level == 1) {
					ele.right_deng.innerHTML = `初级`;
				} else if (arr[0].next_lv.level == 2) {
					ele.right_deng.innerHTML = `中级`;
				} else if (arr[0].next_lv.level == 3) {
					ele.right_deng.innerHTML = `高级`;
				}
				if (item.dataset.ind == 0) {
					// todo渲染家具
					ele.left_chuang.innerHTML = `椅子`;
					ele.right_chuang.innerHTML = `椅子`;
				} else if (item.dataset.ind == 1) {
					ele.left_chuang.innerHTML = `衣柜`;
					ele.right_chuang.innerHTML = `衣柜`;
				} else if (item.dataset.ind == 2) {
					ele.left_chuang.innerHTML = `沙发`;
					ele.right_chuang.innerHTML = `沙发`;
				} else if (item.dataset.ind == 3) {
					ele.left_chuang.innerHTML = `床`;
					ele.right_chuang.innerHTML = `床`;
				} else if (item.dataset.ind == 4) {
					ele.left_chuang.innerHTML = `电视机`;
					ele.right_chuang.innerHTML = `电视机`;
				} else if (item.dataset.ind == 5) {
					ele.left_chuang.innerHTML = `钢琴`;
					ele.right_chuang.innerHTML = `钢琴`;
				}
				// todo渲染能量值
				ele.left_r.innerHTML = `${arr[0].now_lv.luxury}`;
				ele.left_h.innerHTML = `${arr[0].now_lv.power}/时`;
				ele.right_r.innerHTML = `+${arr[0].next_lv.luxury}`;
				ele.right_h.innerHTML = `+${arr[0].next_lv.power}/时`;
				// todo渲染下面的碎片
				ele.yongyou.innerHTML = `${arr[0].has_num}/${arr[0].next_lv.sj_num}`;
				ele.bot_t.innerHTML = `消耗初级${arr[0].name}碎片 <span>${arr[0].next_lv.sj_num}个</span>`;
				// todo赋值id
				id = arr[0].now_lv.id;
				openMdl(ele.modal_confirm);
			};
		});
		// !使用时候
		let right_btn_lvAll = document.querySelectorAll("#right_btn_lv");
		let time = null;
		right_btn_lvAll.forEach((item) => {
			item.onclick = () => {
				if (time) {
					clearTimeout(time);
				}
				time = setTimeout(() => {
					right_btn_lvAsync(item.dataset.id);
				}, 500);
			};
		});
		// !点击卸下
		right_btnAll2.forEach((item) => {
			item.onclick = () => {
				xiexiajai(item.dataset.id);
			};
		});








		// 赵强强

		//  详情
		let item1s = $('.left_img1');
		for (let i = 0; i < item1s.length; i++) {
			// console.log(i);
			item1s[i].onclick = () => {
				// bagList[0].list[i]
				let img = IMG_DOMAIN + bagList[i].now_lv.box.logo
				let name = bagList[i].now_lv.box.name
				let txt = bagList[i].now_lv.box.describe
				let type = '家具'
				let sp_img = _data[i].now_lv.box.level == 0 ?
					'<img class="itemimg2" src="http://img.qxgs.cc/tiantianlaishouzu/img/bag/suipian.png" alt="">' :
					'';
				let pj_type = _data[i].now_lv.box.hammer == 6 ? 'itemred' : _data[i].now_lv.box.hammer == 2 ?
					'itemgreen' : _data[i].now_lv.box.hammer == 3 ? 'itemblue' : _data[i].now_lv.box.hammer ==
					4 ?
					'itempurple' : _data[i].now_lv.box.hammer == 5 ? 'itemorange' : '';
				// let is_show = _data[0].list[i].jj_info.re_id == 3 ? 'none' : 'block'
				// let is_chai = _data[0].list[i].jj_info.level == 0 ? '合成' : '拆分'
				// let is_type = _data[0].list[i].jj_info.level == 0 ? '0' : '1';
				tj_html = '<div class="buffTop">' +
					'<div class="thingimg  ' + pj_type + '">' +
					'<img src="' + img + '" alt="">' +
					sp_img +
					'</div>' +
					'<div class="thingroad">' +
					'<div class="titiler">' +
					'<p>' + name + '</p>' +
					'<span>类型：' + type + '</span>' +
					'</div>' +
					'<p class="remark">' + txt + '</p>' +
					'</div>' +
					'</div>' +
					'<div class="tujing">' +
					'<p>获得途径:</p>' +
					'<div class="ipt-box">' +
					'<span>砸钻蛋</span>' +
					'<a href="leyuan.html"><button>前往</button></a>' +
					'</div>' +
					'<div class="ipt-box">' +
					'<span>原石切割</span>' +
					'<a href="mine3.html"><button>前往</button></a>' +
					'</div>' +
					'</div>'
				// console.log(_data[0].list[i].jj_info.re_id == 3 && _data[0].list[i].jj_info.level != 0);
				// if (_data[0].list[i].jj_info.re_id == 3 && _data[0].list[i].jj_info.level != 0) {
				// 	ele.modalbtn.innerHTML = '<button class="madbtn1" style="display: ' + is_show +
				// 		';" id="hecheng" data="' + bagList[0].list[i].id + '" data2="' + bagList[0].list[i]
				// 		.link_id + '">' + is_chai + '</button>' +
				// 		'<a href="energy_Fang.html"><button class="madbtn2">使用</button></a>'
				// } else {
				// 	ele.modalbtn.innerHTML = '<button class="madbtn1" id="hecheng" data="' + bagList[0].list[i].id +
				// 		'" data2="' + bagList[0].list[i].link_id + '">' + is_chai + '</button>' +
				// 		'<a href="energy_Fang.html"><button class="madbtn2">使用</button></a>'
				// }
				ele.buffList.innerHTML = tj_html;
				openMdl(ele.modal_road);
				let hecheng = $('#hecheng')
				// hecheng.onclick = () => {
				// 	let id = hecheng.getAttribute('data')
				// 	let id2 = hecheng.getAttribute('data2')
				// 	console.log(id);
				// 	if (is_type == 0) {
				// 		jjList(id)
				// 	} else {
				// 		userCfMsg(id, id2)
				// 		// ele.queding.innerHTML = txt
				// 		// openMdl(ele.modal_split);
				// 		// ele.chaiConfirm.onclick = ()=> {
				// 		// 	chaifenList(id)
				// 		// }
				// 	}
				// 	// openMdl(ele.modal_synthesis)
				// }
			}
		}



	}

	function xiexiajai(id) {
		let token = getCookie("token");
		ajax({
			method: "post",
			url: API_PATH.XIEXIAJIA,
			header: {
				Authorization: token,
			},
			data: {
				id: id,
			},
			success: (res) => {
				openTips(res.msg);
				if (res.code == 1) {
					initList();
					asyncList();
				}
			},
			error: (err) => {
				// openTips(err.msg);
			},
		});
	}

	function zhuangxiu() {
		let token = getCookie("token");
		ajax({
			method: "post",
			url: API_PATH.ZHUANGXIU,
			header: {
				Authorization: token,
			},
			data: {
				id: id,
			},
			success: (res) => {
				openTips(res.msg);
				if (res.code == 1) {
					closeMdl(ele.modal_confirm);
					asyncList();
					initList();
				}
			},
			error: (err) => {
				// openTips(err.msg);
			},
		});
	}
	// !使用家具
	function right_btn_lvAsync(id) {
		let token = getCookie("token");
		ajax({
			method: "post",
			url: API_PATH.JIAJUSHIYONG,
			header: {
				Authorization: token,
			},
			data: {
				id: id,
			},
			success: (res) => {
				openTips(res.msg);
				if (res.code == 1) {
					asyncList();
					return;
				}
			},
			error: (err) => {
				// openTips(err.msg);
			},
		});
	}




	// // 合成家具列表
	// function jjList(id) {
	// 	let token = getCookie("token");
	// 	ajax({
	// 		url: API_PATH.JJ_LIST,
	// 		method: 'GET',
	// 		header: {
	// 			'Authorization': token,
	// 		},
	// 		data: {
	// 			id: id // 当前家具碎片id
	// 		},
	// 		success: res => {
	// 			if (res.code == 1) {
	// 				drawlist_hc(res.data)
	// 			} else openTips(res.msg || '未知错误');
	// 		}
	// 	});
	// }

	// // 拆分家具 详情
	// function userCfMsg(id,id2) {
	// 	console.log(id2);
	// 	let token = getCookie("token");
	// 	ajax({
	// 		url: API_PATH.USER_CF_MSG,
	// 		method: 'GET',
	// 		header: {
	// 			'Authorization': token,
	// 		},
	// 		data: {
	// 			id: id2
	// 		},
	// 		success: res => {
	// 			if (res.code == 1) {
	// 				ele.queding.innerHTML = res.data;
	// 				openMdl(ele.modal_split);
	// 				ele.chaiConfirm.onclick = ()=> {
	// 					chaifenList(id)
	// 				}
	// 			} else openTips(res.msg || '未知错误');
	// 		}
	// 	});
	// }








})();